package com.gaojiawei.multiThread05_ThreeSpecialAtomic;

import org.junit.Test;

/**
 * 多线程原子性演示
 * 多线程擦操作临界资源是回出现问题
 */
public class l01_AtomicDemo {

    private static int count;


    @Test
    public void testAtomic() throws InterruptedException {
        Thread thread = new Thread(() -> {
            for (int i = 0; i < 1000; i++) {
                count++;
            }
        });

        Thread thread1 = new Thread(() -> {
            for (int i = 0; i < 1000; i++) {
                count++;
            }
        });

        thread.start();
        thread1.start();
//        thread.join();
//        thread1.join();

        Thread.sleep(5000);
        System.out.println(count);
    }
}
